//
//  BaseViewController.m
//  QuWanWang
//
//  Created by lizq on 15/8/14.
//  Copyright (c) 2015年 tony. All rights reserved.
//

#import "BaseViewController.h"
#import "BaseNavigationViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor whiteColor]];
    self.viewSize = [[UIScreen mainScreen] bounds].size;
    
    self.main = [[UIScrollView alloc] init];
    [self.main setFrame:CGRectMake(0, 44, self.viewSize.width, self.viewSize.height - 44)];
    [self.main setShowsHorizontalScrollIndicator:YES];
    [self.main setShowsVerticalScrollIndicator:YES];
    [self.main setBackgroundColor:[UIColor clearColor]];
    [self.view addSubview:self.main];
    
    self.topView = [[UIView alloc] init];
    [self.topView setFrame:CGRectMake(0, 0, self.viewSize.width, 64)];
    [self.topView setBackgroundColor:UIColorRGB(47, 150, 60)];
    [self.view addSubview:self.topView];
    
    self.titleLabel = [[UILabel alloc] init];
    [self.titleLabel setFrame:CGRectMake(0, 20, self.viewSize.width, 44)];
    [self.titleLabel setTextAlignment:NSTextAlignmentCenter];
    [self.titleLabel setTextColor:[UIColor whiteColor]];
    [self.titleLabel setFont:[UIFont boldSystemFontOfSize:17]];
    [self.view addSubview:self.titleLabel];
    
    self.leftButton = [[UIButton alloc] init];
    [self.leftButton setFrame:CGRectMake(10, 30, 20, 23)];
    [self.leftButton addTarget:self action:@selector(clickBackButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.topView addSubview:self.leftButton];
    
    self.rightButton = [[UIButton alloc] init];
    [self.rightButton setFrame:CGRectMake(self.viewSize.width - 30, 30, 20, 23)];
    [self.rightButton addTarget:self action:@selector(clickRightButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.topView addSubview:self.rightButton];
}

- (void)initRightButtonDef:(NSString *)def sel:(NSString *)sel {
    [self.rightButton setImage:[UIImage imageNamed:def] forState:UIControlStateNormal];
//    [self.rightButton setImage:[UIImage imageNamed:sel] forState:UIControlStateHighlighted];
    [self.rightButton addTarget:self action:@selector(clickRightButton:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)initRightButtonWithTitile:(NSString *)title {
    [self.rightButton setFrame:CGRectMake(self.viewSize.width - 60, 30, 50, 23)];
    [self.rightButton setTitle:title forState:UIControlStateNormal];
    [self.rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.rightButton setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    [self.rightButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
}

- (void)initTitle:(NSString *)title {
    [self.titleLabel setText:title];
}

- (void)initLeftButtonDef:(NSString *)def sel:(NSString *)sel {
    [self.leftButton setImage:[UIImage imageNamed:def] forState:UIControlStateNormal];
//    [self.leftButton setImage:[UIImage imageNamed:sel] forState:UIControlStateHighlighted];
    [self.leftButton addTarget:self action:@selector(clickBackButton:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)initLeftButtonWithTitle:(NSString *)title {
    [self.leftButton setFrame:CGRectMake(10, 30, 50, 23)];
    [self.leftButton setTitle:title forState:UIControlStateNormal];
    [self.leftButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.leftButton setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    [self.leftButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
}

- (void)clickBackButton:(UIButton *)btn {
    [(BaseNavigationViewController *)self.navigationController popViewController:self bAnimaiton:YES];
}

- (void)clickRightButton:(UIButton *)btn {
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark framde delegate
- (CGRect)beginFrame {
    return CGRectMake(self.view.frame.size.width, 0,self.view.frame.size.width , self.view.frame.size.height);
}

- (CGRect)endFrame {
    return CGRectMake(0, 0,self.view.frame.size.width , self.view.frame.size.height);
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
